﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_DSGioHang : System.Web.UI.Page
{
    private DataSet objShoppingCartDS;
    protected void Page_Load(object sender, EventArgs e)
    {
        // Set the title of the page
        this.Title = TGDDConfiguration.SiteName +
                      " : quản lý giỏ hàng";
    }
    // deletes old shopping carts
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int days = byte.Parse(lstDays.SelectedItem.Value);
        GioHangBUS objShoppingCart =
            new GioHangBUS(TGDDConfiguration.DbConnectionString);
        try
        {
            objShoppingCart.DeleteOldCartsFromGioHang(days);
            lblCount.Text = "Các đơn đặt hàng để quá lâu đã được xóa khỏi database";
        }
        catch (System.Exception ex)
        {
            throw new Exception(ex.Message, ex.InnerException);
        }
    }
    protected void btnCount_Click(object sender, EventArgs e)
    {
        int days = byte.Parse(lstDays.SelectedItem.Value);
        GioHangBUS objShoppingCart =
            new GioHangBUS(TGDDConfiguration.DbConnectionString);
        try
        {
            objShoppingCartDS = objShoppingCart.CountOldCartsInGioHang(days);
            DataRow row =
                objShoppingCartDS.Tables[0].Rows[0];
            int oldItems = int.Parse(row[0].ToString());
            if (oldItems == -1)
                lblCount.Text = "Could not count the old shopping carts!";
            else if (oldItems == 0)
                lblCount.Text = "Không có giỏ hàng nào quá lâu để xóa!";
            else
                lblCount.Text = "Tìm thấy " + oldItems.ToString() +
                                  " giỏ hàng.";
        }
        catch (System.Exception ex)
        {
            throw new Exception(ex.Message, ex.InnerException);
        }
    }
}
